/**
 * @file TEST_scififo.c
 * @author Linquan 
 * @brief 
 * @version 0.1
 * @date 2025-09-22
 * 
 * @copyright Copyright (c) 2025
 * 
 */

#include "app_config.h"

#if TEST_TEST_SCIFIFO

#include "scififo.h"


DECLARE_SCIFIFO(u8_scififo, uint8_t, 32);

void u8_data_scififo_test()
{
    uint8_t u8_data[16] = {1, 2,3,4,5,6,7,8,9,0,10,11,12,13};
    uint8_t u8_read_data[10] ;
    uint8_t  read_from_in, read_from_out;

    /* 初始化缓冲区 */
    INIT_SCIFIFO(u8_scififo);


    _scififo_append(SCIFIFO(u8_scififo), &u8_data, 10);


    _scififo_at_out(SCIFIFO(u8_scififo) , &read_from_out, 0);
    printf("index from out ptr's data is  %d \r\n",read_from_out);

    _scififo_at_in(SCIFIFO(u8_scififo), &read_from_in, 2);
    printf("index from in ptr's data is  %d \r\n",read_from_in);


    _scififo_remove(SCIFIFO(u8_scififo), &u8_read_data, 5);

    for(int i  = 0; i<5; i++)
   {
        printf("u8_read_data %d \r\n",u8_read_data[i]);
   }
    printf("the first length %d \r\n",_scififo_length(SCIFIFO(u8_scififo))); 


    _scififo_remove(SCIFIFO(u8_scififo), NO_BUFF, 5);

    printf("the secoond length %d \r\n",_scififo_length(SCIFIFO(u8_scififo))); 

}







typedef struct 
{
    uint8_t data1;
    uint16_t data2;
}str_data_t;


DECLARE_SCIFIFO(struct_scififo, str_data_t, 4);

void struct_scififo_test()
{
    str_data_t u8_data[4] = {{1,11},{2,22},{3,33},{4,44}};
    str_data_t new_data = {10,11};
    str_data_t u8_read_data[4] ;
    str_data_t  read_from_in, read_from_out;

    /* 初始化缓冲区 */
    INIT_SCIFIFO(struct_scififo);

    _scififo_append(SCIFIFO(struct_scififo), &u8_data, 4);

    _scififo_at_out(SCIFIFO(struct_scififo) , &read_from_out, 0);
    printf("index from out ptr's data is  %d %d \r\n",read_from_out.data1, read_from_out.data2 );

    _scififo_at_in(SCIFIFO(struct_scififo), &read_from_in, 2);
    printf("index from in ptr's data is  %d %d \r\n",read_from_in.data1, read_from_out.data2);

    /*退出一个值，填入一个新值 */
    _scififo_remove(SCIFIFO(struct_scififo), NO_BUFF, 1);
    _scififo_append(SCIFIFO(struct_scififo), &new_data, 1);

    /* 直接抛弃两个值，不保存 */
    _scififo_remove(SCIFIFO(struct_scififo), NO_BUFF, 2);
    printf("remove without buff, the first length %d \n", _scififo_length(SCIFIFO(struct_scififo))); 

    /* 取出两个值，保存到缓冲区 */
    _scififo_remove(SCIFIFO(struct_scififo), &u8_read_data, 2);

    for(int i  = 0; i<2; i++)
   {
        printf("struct_read_data %d, %d \r\n",u8_read_data[i].data1, u8_read_data[i].data2 );
   }
    printf("remove data with buff, the second length %d \r\n",_scififo_length(SCIFIFO(struct_scififo))); 
   
}





void TEST_scififo()
{
   printf("-------type is  uint8_t ,size is 1 ------\r\n");
    u8_data_scififo_test();

    printf("------type is  struct ,size is not 1 ------\r\n");
    struct_scififo_test();

}


EXPORT_Lv6_APP_SINGLE(TEST_scififo,NULL);


// foreach(uint8_t, u8_data, ptItem) 
// {
//     printf("Processing item with ID by three parament  = %d\r\n", ptItem->chID);
// }
















#endif

































